<%-- 
    Document   : ApplyImport
    Created on : 08.12.2011, 21:28:10
    Author     : Николай
--%>

<%@page import="DBConnection.ATeamObject"%>
<%@page import="java.util.HashMap"%>
<%@page import="javax.rmi.PortableRemoteObject"%>
<%@page import="manufacturerBean.ManufacturerHome"%>
<%@page import="manufacturerBean.Manufacturer"%>
<%@page import="categoryBean.Category"%>
<%@page import="categoryBean.CategoryHome"%>
<%@page import="goodsBean.Goods"%>
<%@page import="goodsBean.GoodsHome"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="java.util.Map"%>
<%@ page errorPage = "Error.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Разрешение конфликтов</title>
    </head>
    <body background="1.jpg" bgproperties="fixed">
        <% 
           InitialContext initialContext = new InitialContext();

           GoodsHome goodsHome;
           Goods goods;
           Object homeObject;

           CategoryHome categoryHome;
           Category category;
           Object homeObject1;

           Manufacturer manufacturer;
           ManufacturerHome manufacturerHome;
           Object homeObject2;

           homeObject = initialContext.lookup("GoodsBean");
           goodsHome = (GoodsHome) PortableRemoteObject.narrow(homeObject,
                    GoodsHome.class);

           homeObject1 = initialContext.lookup("CategoryBean");
           categoryHome = (CategoryHome) PortableRemoteObject.narrow(
                   homeObject1,CategoryHome.class);

           homeObject2 = initialContext.lookup("ManufacturerBean");
           manufacturerHome = (ManufacturerHome) PortableRemoteObject.narrow(
                   homeObject2,ManufacturerHome.class);

           Map resolvableProblem = (HashMap)request.getSession().getAttribute(
                   "resolvableProblem");

           String[] updateObjects = request.getParameterValues("updateObject");
           if (updateObjects != null) {
               for(int i = 0; i < updateObjects.length; i++) {
                   ATeamObject ato = (ATeamObject)resolvableProblem.get(
                           Integer.parseInt(updateObjects[i]));

                   if(ato.getTypeOfObject() == 1){
                       category = categoryHome.findByPrimaryKey(
                               ato.getObjectId());
                       category.setName(ato);
                       category.setParentId(ato);
                       category.setObjectDescription(ato);
                   }

                   if(ato.getTypeOfObject() == 2){
                       manufacturer = manufacturerHome.findByPrimaryKey(
                               ato.getObjectId());
                       manufacturer.setName(ato);
                       manufacturer.setParentId(ato);
                       manufacturer.setObjectDescription(ato);
                   }

                   if(ato.getTypeOfObject() == 4){
                       goods = goodsHome.findByPrimaryKey(ato.getObjectId());
                       goods.setNameOfGoods(ato.getName());
                       goods.setGoodsDescription(ato.getObjectDescription());
                       goods.setNumber(ato.getNumber());
                       goods.setPrice(ato.getPrice());
                       goods.setCategoryId(ato.getParentId());
                       goods.setManufactureId(ato.getManufacturerId());
                   }
               }
           }
        %>
        <script language="javascript">
            alert("Конфликты успешно разрешены!");
            document.location.href = "index.jsp";
        </script>
    </body>
</html>
